home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / AddXheader.rexx next >
OS/2 REXX Batch file  |  1997-04-14  |  2KB  |  72 lines

  1. /* AddXheader.rexx 1.1 by knikulai@utu.fi 
  2. ** Adds X-Headers from a given file to all messages in the outgoing folder
  3. ** Check http://www.utu.fi/~knikulai/ARexx.html for more scripts or send mail
  4. ** to knikulai@utu.fi with word 'request' as subject and 'dir' in message body 
  5. ** 
  6. ** This version doesn't add same headers many times.
  7. */
  8. options results
  9.  
  10. headers='YAM:xheaders'    /* File to read headers from.  Empty lines are ignored */
  11.             /* Header format is _NOT_ checked in any way, it's your */
  12.             /* responsibility */
  13. tempfile='t:tmp.msg'
  14.  
  15. address 'YAM'         /* Our favourite program.. */
  16.  
  17. if ~open(hdr,headers,'r') then do /* Something went wrong... Is the path correct? */
  18.     'Request "Could not open' headers'!" "_Ok"'
  19.     exit
  20.     end
  21.  
  22. /* Read the header file:*/
  23. lines=0
  24. do while ~eof(hdr)
  25.     li=strip(readln(hdr))
  26.     if li~='' then do    /* Forget empty lines */
  27.         lines=lines+1
  28.         header.lines=li
  29.         end
  30.     end
  31. call close(hdr)
  32.  
  33. 'SetFolder 1'
  34. 'GetFolderInfo Max'
  35. n=result
  36. if n=0 then do
  37.     'Request "The Outgoing folder is empty!" "_Ok"'
  38.     exit
  39.     end
  40.  
  41. do m=0 to n-1
  42.     'SetMail' m        /* Change message */
  43.     'GetMailInfo File'    /* Get it's filename */
  44.     file=result
  45.     address command 'c:copy' file tempfile    /* Copy the message */
  46.     call open(in,tempfile,'r')        /* Open copy for reading */
  47.     call open(out,file,'w')            /* Open message for rewrite */
  48.  
  49.     body=0                     /* This means we are still in headers */
  50.     add_here=0                /* Add headers when this is 1*/
  51.     do while ~eof(in)
  52.         li=readln(in)            /* Read a line from copy */
  53.         if add_here & word(li,1)~=word(header.1,1) & ~body then do
  54.             body=1            /* Make sure we wont do this again */
  55.             do i=1 to lines        /* Write all headers */
  56.                 call writeln(out,header.i)
  57.                 end
  58.             end /* if */
  59.         call writeln(out,li)        /* Write the line */
  60.         /* Change the following line and you can decide after which header */
  61.         /* line the new lines are added. */
  62.         if word(li,1)='Message-ID:' & ~body then 
  63.             add_here=1
  64.         else
  65.             add_here=0
  66.         end /* do while */
  67.     call close(in)                /* Close copy */
  68.     call close(out)                /* Close new message */
  69. end
  70. address command 'c:delete >nil:' tempfile    /* Delete the copy of the last msg */
  71. exit
  72.